home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume90
/
unix
/
cat
/
cat.c
next >
Wrap
C/C++ Source or Header
|
1990-02-02
|
817b
|
52 lines
/* cat - amiga program to concatenate files, requires ANSI C */
/* Released to the public domain by Karl Lehenbauer, 1-Feb-1990 */
#include <stdio.h>
#include <fcntl.h>
void catfile(const char *fname)
{
FILE *fp;
char s[1024];
if ((fp = fopen(fname,"r")) == NULL)
{
perror(fname);
return;
}
while (fgets(s, sizeof(s), fp) != NULL)
fputs(s, stdout);
if (ferror(fp))
fprintf(stderr,"cat: error occured reading %s\n",fname);
fclose(fp);
}
main(int argc, char *argv[])
{
char *fname;
int i;
if (argc < 2)
{
fprintf(stderr,"usage: cat [>outfile] file [file..]\n");
exit(1);
}
for (i = 1; i < argc; i++)
while ((fname = scdir(argv[i])) != NULL)
catfile(fname);
if (ferror(stdout))
{
fprintf(stderr,"cat: error occured while writing output file\n");
exit(2);
}
exit(0);
}